home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Watcher.c
- Main source file for Watcher, a sample QuickTime Conferencing application
- Loosely on Philco, a SeeWorld extravaganza, courtesy Guy Riddle.
-
- Copyright: © 1995 by Apple Computer, Inc.
- All rights reserved.
- */
-
- /* Includes ****************************************/
- #define SystemSevenOrLater 1
- #include <DiskInit.h>
- #include <Fonts.h>
- #include <Resources.h>
- #include <AppleEvents.h>
- #include <ToolUtils.h>
- #include <SegLoad.h>
- #include <Devices.h>
- #include <String.h>
-
- #include "QuickTimeConferencing.h"
-
- #include "watcher.h"
- #include "watching.h"
- #include "shared.h"
-
- /* Prototypes **************************************/
- void InitMac( void );
-
- ComponentResult InitApp( void );
-
- void EventLoop( void );
-
- Boolean ProcessUserEvent( void );
- Boolean HandleMouseDown( EventRecord* currEvent );
- Boolean HandleKeyDown( EventRecord* currEvent );
- Boolean HandleHighLevelEvent( EventRecord* currEvent);
- void HandleDiskEvent( EventRecord* currEvent );
-
- void AdjustMenus( void );
- Boolean HandleMenuItem( long selection );
- Boolean HandleAppleMenu( short menuItem );
- Boolean HandleFileMenu( short menuItem );
- Boolean HandleEditMenu( short menuItem );
-
- ComponentResult DoWatch(void);
- ComponentResult BrowseName( MTNamePtr name );
-
- /***************************************************
- InitApp
- ****************************************************/
- ComponentResult InitApp( void ) {
-
- ComponentResult result = noErr;
- Handle menuBar;
- Str63 userName;
-
- menuBar = GetNewMBar(kMenuBarID);
- if (menuBar)
- {
- SetMenuBar(menuBar);
- DisposHandle(menuBar);
- AddResMenu(GetMHandle(kAppleMenuID), 'DRVR');
- DrawMenuBar();
- }
- else
- result = ResError();
-
- /* open up the standard QTC conference component */
- if (result == noErr)
- {
- GetUserName( userName );
- result = CreateWatchConference( userName );
- }
-
- return result;
- }
-
- /***************************************************
- Main
- ****************************************************/
- void main( void ) {
-
- ComponentResult result = noErr;
-
- DialogPtr splash;
-
- InitMac();
-
- splash = OpenSplashScreen();
-
- result = InitApp();
-
- if (splash)
- DisposDialog(splash);
-
- if (result == noErr)
- EventLoop();
- else
- DisplayErrorAlert( result );
-
- TearDownWatch();
-
- ExitToShell();
- }
-
- /***************************************************
- InitMac
- ****************************************************/
- void InitMac( void ) {
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- EnterMovies();
- }
-
- /***************************************************
- EventLoop
- ****************************************************/
- void EventLoop( void ) {
-
- Boolean bail;
-
- do {
-
- DisplayErrorAlert( CheckConferenceEvents() );
-
- bail = ProcessUserEvent();
-
- } while (bail == false);
- }
-
-
- /***************************************************
- ProcessUserEvent
- ****************************************************/
- Boolean ProcessUserEvent( void ) {
- Boolean bail = false;
- EventRecord currEvent;
-
- WaitNextEvent(everyEvent, &currEvent, 1, 0);
-
- if( !IsConferenceEvent( &currEvent) )
- {
- switch (currEvent.what) {
- case mouseDown:
- bail = HandleMouseDown( &currEvent );
- break;
-
- case keyDown:
- bail = HandleKeyDown( &currEvent );
- break;
-
- case kHighLevelEvent:
- bail = HandleHighLevelEvent( &currEvent);
- break;
-
- case diskEvt:
- HandleDiskEvent( &currEvent );
- break;
-
- default:
- break;
- }
- }
- return bail;
- }
-
-
- /***************************************************
- HandleMouseDown
- ****************************************************/
- Boolean HandleMouseDown( EventRecord* currEvent ) {
- Boolean bail = false;
- WindowPtr eventWindow;
- short part;
- long whichMenuItem;
-
- part = FindWindow(currEvent->where, &eventWindow);
-
- switch(part){
- case inMenuBar:
- AdjustMenus();
- whichMenuItem = MenuSelect( currEvent->where );
- bail = HandleMenuItem( whichMenuItem );
- break;
- case inDrag:
- DragWindow( eventWindow, currEvent->where, &(*GetGrayRgn())->rgnBBox );
- break;
- case inGoAway:
- if (TrackGoAway( eventWindow, currEvent->where ) )
- CloseWatch( eventWindow );
- break;
- default:
- break;
- }
-
- return bail;
- }
-
- /***************************************************
- HandleKeyDown
- ****************************************************/
- Boolean HandleKeyDown( EventRecord* currEvent ) {
- Boolean bail = false;
- long whichMenuItem;
-
- if(currEvent->modifiers & cmdKey){
-
- AdjustMenus();
-
- whichMenuItem = MenuKey(currEvent->message & charCodeMask);
-
- bail = HandleMenuItem(whichMenuItem);
- }
-
- return bail;
- }
-
- /***************************************************
- HandleHighLevelEvent
- ****************************************************/
- Boolean HandleHighLevelEvent( EventRecord* currEvent) {
-
- Boolean bail = false;
-
- AEProcessAppleEvent(currEvent);
-
- return bail;
- }
-
- /***************************************************
- HandleDiskEvent
- ****************************************************/
- void HandleDiskEvent( EventRecord* currEvent ) {
- Point where;
-
- if(HiWord(currEvent->message)){
- SetPt(&where, kDILeft, kDITop);
- DIBadMount(where, currEvent->message);
- }
- }
-
- /***************************************************
- HandleMenuItem
- ****************************************************/
- Boolean HandleMenuItem( long selection ) {
- Boolean bail = false;
- short menuID = HiWord(selection);
- short menuItem = LoWord(selection);
-
- switch (menuID) {
- case kAppleMenuID:
- bail = HandleAppleMenu( menuItem );
- break;
- case kFileMenuID:
- bail = HandleFileMenu( menuItem );
- break;
- case kEditMenuID:
- bail = HandleEditMenu( menuItem );
- break;
- }
-
- HiliteMenu(0);
-
- return bail;
- }
-
- /***************************************************
- HandleAppleMenu
- ****************************************************/
- Boolean HandleAppleMenu( short menuItem ) {
- Boolean bail = false;
- Str255 daName;
-
- switch (menuItem) {
- case kAboutMenuItem:
- DoAboutBox();
- break;
-
- default: /* all non-About items in this menu are DAs */
- GetItem(GetMHandle(kAppleMenuID), menuItem, daName);
- OpenDeskAcc(daName);
- }
-
- return bail;
- }
-
- /***************************************************
- HandleFileMenu
- ****************************************************/
- Boolean HandleFileMenu( short menuItem ) {
- Boolean bail = false;
- ComponentResult err;
-
- switch (menuItem) {
- case kWatchMenuItem:
- err = DoWatch();
- break;
- case kSaveWatchMenuItem:
- SaveWatch();
- break;
- case kCloseWatchMenuItem:
- err = CloseWatch( FrontWindow() );
- /* check to see if this wasn't a watch window for some reason */
- if (err == paramErr)
- err = noErr;
- break;
- case kGetWatchInfoMenuItem:
- GetWatchInfo();
- break;
- case kQuitMenuItem:
- bail = true;
- break;
- default: /* there shouldn't be any */
- break;
- }
-
- DisplayErrorAlert( err );
-
- return bail;
- }
-
- /***************************************************
- HandleEditMenu
- ****************************************************/
- Boolean HandleEditMenu( short menuItem ) {
- Boolean bail = false;
- Boolean handled;
-
- handled = SystemEdit(menuItem-1);
-
- if (!handled ) /* if this is our edit... */
- {
- switch (menuItem) {
- case kCopyMenuItem:
- DoCopy();
- break;
- default: /* we only know how to copy now... */
- break;
- }
- }
-
- return bail;
- }
-
- /***************************************************
- AdjustMenus
- ****************************************************/
- void AdjustMenus( void ) {
- MenuHandle appleMenu = GetMHandle(kAppleMenuID);
- MenuHandle fileMenu = GetMHandle(kFileMenuID);
- MenuHandle editMenu = GetMHandle(kEditMenuID);
-
- EnableItem( appleMenu, kAboutMenuItem );
- EnableItem( fileMenu, kQuitMenuItem );
-
- if (IsWatchWindow( FrontWindow() ) )
- {
- EnableItem( fileMenu, kCloseWatchMenuItem );
- EnableItem( fileMenu, kSaveWatchMenuItem );
- EnableItem( fileMenu, kGetWatchInfoMenuItem );
- EnableItem( editMenu, kCopyMenuItem );
- }
- else
- {
- DisableItem( fileMenu, kCloseWatchMenuItem );
- DisableItem( fileMenu, kSaveWatchMenuItem );
- DisableItem( fileMenu, kGetWatchInfoMenuItem );
- DisableItem( editMenu, kCopyMenuItem );
- }
-
- DisableItem( editMenu, kUndoMenuItem );
- DisableItem( editMenu, kCutMenuItem );
- DisableItem( editMenu, kPasteMenuItem );
- DisableItem( editMenu, kClearMenuItem );
- }
-
- /***************************************************
- DoWatch
- ****************************************************/
- ComponentResult DoWatch(void) {
-
- ComponentResult err = noErr;
- WindowPtr wind = nil;
- Rect box = { 0, 0, 160, 120 + 16 };
- MTName name;
-
- err = BrowseName( &name );
-
- if ( err == noErr )
- {
- wind = GetNewCWindow(kWatchWindowID, nil, (GrafPtr)-1);
- if (wind) {
- MemberRecord* member;
- /* just call the first name in the list... */
- err = CallMember( &name, wind, &box, true, &member );
-
- /* save it away in the refcon for later use */
- if (err == noErr)
- {
- SetWRefCon(wind, (long)member);
- }
- }
-
- if (err != noErr)
- DisposeWindow( wind );
- }
-
- if (err == userCanceledErr)
- err = noErr;
-
- return err;
- }
-
- /***************************************************
- BrowseName
- ****************************************************/
- ComponentResult BrowseName( MTNamePtr name ) {
- MTNameListPtr allNames = 0;
- ComponentResult err;
- MTBrowserComponent browser = nil;
-
- browser = OpenDefaultComponent(kMTBrowserType, kMTAppleTalkSubType);
-
- if (browser)
- {
- err = MTBrowserBrowse(browser, 0, nil, (MTCString)"mtlkatlk\tMulticaster\x0D", 0, &allNames);
-
- CloseComponent( browser );
- }
- else
- err = couldntGetRequiredComponent;
-
- if (allNames)
- {
- /* copy the name record */
- *name = allNames->list[0];
-
- /* dispose of the list of names */
- DisposePtr((Ptr)allNames);
- }
-
- return err;
- }